/**
 * @Title: Issue.java 
 * @Description: TODO
 * @author <a href="mailto:psammead@126.com">Psammead</a>
 * @date 2011-7-16 上午09:44:59 
 * @version 1.0
 * Copyright 2011 by Psammead
 */
package com.psammead.dms.project.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.psammead.dms.common.core.bo.AbstractBaseBO;
import com.psammead.dms.system.sercurity.entity.SysUser;

/**
 * 项目问题实体
 * @ClassName: Issue
 * @Description: TODO
 * @author <a href="mailto:psammead@126.com">psammead</a>
 * @version 1.0
 * @date 2011-7-16
 */
@Entity(name="Issue")
@Table(name="tb_pm_issue")
public class Issue extends AbstractBaseBO implements Serializable {

	/**
	 * @Fields serialVersionUID 
	 */
	private static final long serialVersionUID = 1244356182487243163L;
	private long id;
	private String title;
	private Project project;
	private String status;
	private String description;
	private String comment;
	private String solution;
	private Date createTime;
	private Date updateTime;
	private SysUser creator;
	private SysUser updater;
	private SysUser closer;
	private SysUser charger;
	private Date planCloseTime;
	private Date actCloseTime;
	
	private Set<ProjectAttach> attachs=new HashSet<ProjectAttach>();
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="issue_id")
	@Override
	public long getId() {
		// TODO Auto-generated method stub
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}
	
	@Column(name="title")
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@ManyToOne(fetch=FetchType.LAZY, cascade={CascadeType.MERGE,
			CascadeType.REFRESH},optional=true)
	@JoinColumn(name="project_id")
	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	@Column(name="status")
	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}
	
	@Column(name="description",length=2000)
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name="comment",length=2000)
	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	@Column(name="solution",length=2000)
	public String getSolution() {
		return solution;
	}

	public void setSolution(String solution) {
		this.solution = solution;
	}

	@Column(name="create_time")
	@Temporal(value=TemporalType.DATE)
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	@Column(name="update_time")
	@Temporal(value=TemporalType.DATE)
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@ManyToOne(fetch=FetchType.LAZY, cascade={CascadeType.MERGE,
			CascadeType.REFRESH},optional=true)
	@JoinColumn(name="creator")
	public SysUser getCreator() {
		return creator;
	}

	public void setCreator(SysUser creator) {
		this.creator = creator;
	}

	@ManyToOne(fetch=FetchType.LAZY, cascade={CascadeType.MERGE,
			CascadeType.REFRESH},optional=true)
	@JoinColumn(name="updater")
	public SysUser getUpdater() {
		return updater;
	}

	public void setUpdater(SysUser updater) {
		this.updater = updater;
	}

	@ManyToOne(fetch=FetchType.LAZY, cascade={CascadeType.MERGE,
			CascadeType.REFRESH},optional=true)
	@JoinColumn(name="closer")
	public SysUser getCloser() {
		return closer;
	}

	public void setCloser(SysUser closer) {
		this.closer = closer;
	}

	@ManyToOne(fetch=FetchType.LAZY, cascade={CascadeType.MERGE,
			CascadeType.REFRESH},optional=true)
	@JoinColumn(name="charger")
	public SysUser getCharger() {
		return charger;
	}

	public void setCharger(SysUser charger) {
		this.charger = charger;
	}


	@Column(name="plan_close_time")
	@Temporal(value=TemporalType.DATE)
	public Date getPlanCloseTime() {
		return planCloseTime;
	}

	public void setPlanCloseTime(Date planCloseTime) {
		this.planCloseTime = planCloseTime;
	}

	@Column(name="act_close_time")
	@Temporal(value=TemporalType.DATE)
	public Date getActCloseTime() {
		return actCloseTime;
	}

	public void setActCloseTime(Date actCloseTime) {
		this.actCloseTime = actCloseTime;
	}
	
	@OneToMany(mappedBy="issue",cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	public Set<ProjectAttach> getAttachs() {
		return attachs;
	}

	public void setAttachs(Set<ProjectAttach> attachs) {
		this.attachs = attachs;
	}
	
	public void addAttach(ProjectAttach attach) {  
        if (!this.attachs.contains(attach)) {  
            this.attachs.add(attach);  
            attach.setIssue(this);
        }  
    }  
    public void removeAttach(ProjectAttach attach) {  
    	attach.setIssue(null);  
        this.attachs.remove(attach);  
    }

}
